package com.tedu.admin.controller;

import com.tedu.common.response.JsonResult;
import com.tedu.admin.pojo.dto.AdminLoginParam;
import com.tedu.admin.pojo.dto.AdminQuery;
import com.tedu.admin.pojo.dto.AdminSaveParam;
import com.tedu.admin.pojo.vo.AdminVO;
import com.tedu.admin.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/p1/admin")
@Slf4j
public class AdminController {
    @Autowired
    AdminService adminService;

    @PostMapping("/login")
    public JsonResult login(@RequestBody AdminLoginParam adminLoginParam) {
        log.debug("管理员名登录：{}", adminLoginParam);
        AdminVO adminVO = adminService.login(adminLoginParam);
        return JsonResult.ok(adminVO);
    }

    @PostMapping("/save")
    public JsonResult saveAdmin(AdminSaveParam adminSaveParam) {
        log.debug("保存管理员：{}", adminSaveParam);
        adminService.save(adminSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("/select")
    public JsonResult selectAdmin(AdminQuery adminQuery) {
        log.debug("查询管理员：{}", adminQuery);
        List<AdminVO> list = adminService.selectAdmin(adminQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/update/password/{adminId}")
    public JsonResult resetPssword(@PathVariable Long adminId) {
        log.debug("重置密码：{}", adminId);
        adminService.resetPassword(adminId);
        return JsonResult.ok();
    }

    @PostMapping("/update/status/{adminId}/{status}")
    public JsonResult updateStatus(@PathVariable Long adminId, @PathVariable String status) {
        log.debug("修改管理员状态：{},{}", adminId, status);
        adminService.updateStatus(adminId, status);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/{adminId}")
    public JsonResult deleteAdmin(@PathVariable Long adminId) {
        log.debug("删除管理员：{}", adminId);
        adminService.deleteAdmin(adminId);
        return JsonResult.ok();
    }

    @GetMapping("/select/audit/{parentId}")
    public JsonResult selectAuditList(@PathVariable Long parentId){
        log.debug("查询审批人列表：{}",parentId);
        List<AdminVO> list = adminService.selectAuditList(parentId);
        return JsonResult.ok(list);
    }

}
